var fs = require('fs');
var log4js = require('log4js');
var logger = log4js.getLogger('normal');

/**
 * 开发环境的keys
 * @type {{APP_ID: string, APP_KEY: string, MASTER_KEY: string}}
 */
var DEV_KEYS = {
    APP_ID:'64yipwcn159l9ehdf3j3x3xz1f1ly9r89x9gf7i2d1282dvz',
    APP_KEY:'w3xp0oibbzhweamm76ogo6r5dyzt82tczw7lssfvyj6hlarv',
    MASTER_KEY:'zlf6rkt286shvykgo08dht3938tg3ln2idvfcu7t61h1ngfq'
};

/**
 * 预发布环境的keys
 * @type {{APP_ID: *, APP_KEY: *, MASTER_KEY: *}}
 */
var STAGING_KEYS = {
    APP_ID:'32co2g21ef1quhvwjl9ok7u4upqvha6d8kv0vas2rstiqbly',
    APP_KEY:'n0xpioh693t6fa3l1kjyu32lbubrr0kj6tsupothw8xl21c9',
    MASTER_KEY:'qh2pmum52zlctzvc9o04aitepvbt75t35snpwkl19398gye7'
}

/**
 * 生产环境的keys
 * @type {{APP_ID: *, APP_KEY: *, MASTER_KEY: *}}
 */
var PRODUCT_KEYS = {
    APP_ID:'8c4dst8wuiimm9nxj8puwrqrhmkxegkl2ittuy6a2jkmx1pl',
    APP_KEY:'6lqn0keuf89uzoj8px4t47u9e39eimx7jo7ad1qy9pd125nm',
    MASTER_KEY:'lgdpvs1cjc2nab37rlkv6i34hfi6q6r0n87ut5ootaebdndp'
}


/**
 * 开发环境中的wx应用信息
 * @type {{app_id: string, app_secret: string}}
 */
var WX_DEV_KEYS = {
    app_id:'wxef9f343d05b97ba0',
    app_secret:'e26a35f3bf82b55de3dc01ffec680909',
    cache_json_file:'cache',
    pay:{
        appid: 'wxef9f343d05b97ba0',
        mch_id: '1247833301',
        partner_key: 'defe9460b5bcdaaa545eb7227b008cfe', //微信商户平台API密钥
        pfx:fs.readFileSync('./wxpay_cert.p12'), //微信商户平台证书
    },
    open_id : 'oA7dTszNX7jPucCFmXPlea7C7A1s'
};
//微信正式号
var WX_PRODUCT_KEYS = {
    app_id:'wx0e5dece83e52048b',
    app_secret:'faa1185e5271825afaee4ea2e20e1ab8',
    cache_json_file:'cache',
    pay:{
        appid: 'wx0e5dece83e52048b',
        mch_id: '1218940201',
        partner_key: '295222888a640c4cf75c676f83f689c7', //微信商户平台API密钥
        //pfx:fs.readFileSync('./wxpay_cert.p12'), //微信商户平台证书
    }
};
/**
 * 可选项：DEV , STAGING , PRODUCT
 * @type {string}
 */
//var dev = 'STAGING';
//var dev = 'DEV';
var dev = (function(){
    if('linux' == process.platform){
        //在linux环境中运行
        if(__dirname.indexOf('mguoran100')>0 || __dirname.indexOf('data/www/GR_WeiStore')>0){
            logger.info('在正式环境中启动!');
            return 'PRODUCT';
        }
        //判断执行的目录
        logger.info('在沙箱环境中启动!');
        return 'STAGING';
    }
    logger.info('在测试环境中启动!');
    return 'DEV';
})();
var DEV_DOMAIN = 'mdev.guoran100.com';

var PRODUCT_DOMAIN = 'wxshop.guoran100.com';

exports.dev = dev;

exports.CloudKeys = (function(){
    switch (dev){
        case 'DEV':
            return DEV_KEYS;
            //return STAGING_KEYS;
        case 'STAGING':
                return DEV_KEYS;
                //return STAGING_KEYS;
        case 'PRODUCT':
            return PRODUCT_KEYS;
    }
})();

exports.config = (function(){
    switch (dev){
        case 'DEV':
            return {
                cndhost:"http://127.0.0.1:3000//",
            };
        case 'STAGING':
            return {
                cndhost:"http://mdev.guoran100.com//",
            };
        case 'PRODUCT':
            return {
                cndhost:"http://wxshop.guoran100.com//",
            };
    }
})();

exports.port = (function(){
    if(dev == 'STAGING') {
        return '2000';
    }
    return '3000';
})();
exports.wx = (function(){
    switch (dev){
        case 'DEV':
            //return WX_DEV_KEYS;
        case 'STAGING':
            return WX_DEV_KEYS;
        case 'PRODUCT':
            return WX_PRODUCT_KEYS;
    }
})();

exports.domain = (function(){
    switch (dev){
        case 'DEV':
            return DEV_DOMAIN;
        case 'STAGING':
            return DEV_DOMAIN;
        case 'PRODUCT':
            return PRODUCT_DOMAIN;
    }
})();


exports.log4js = {
    appenders: [
        { type: 'console' },{
            type: 'file',
            filename: 'logs/access.log',
            maxLogSize: 1024 * 1024 * 100, //100Mb一个文件
            backups:10,
            category: 'normal'
        }
    ],
    replaceConsole: true
};

exports.mail_opts = {
    host: 'smtp.126.com',
        port: 25,
        auth: {
        user: 'club@126.com',
            pass: 'club'
    }
};

exports.mongoDB = (function(){
    switch (dev){
        case 'DEV':
        return 'mongodb://192.168.1.218:27017/efresh';
        case 'STAGING':
            return 'mongodb://180.150.187.159:27017/efresh-staging';
        case 'PRODUCT':
            if(__dirname.indexOf('data/www/GR_WeiStore')>0){
                return 'mongodb://180.150.187.159:27017/efresh-product';
            }else{
                return 'mongodb://61.147.98.134:27017/efresh-product';
            }

    }
})();
